package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mes.vo.line.annualVo;
import com.ruoyi.mes.vo.line.dailyVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.ProductionLine;
import com.ruoyi.mes.service.IProductionLineService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产线信息Controller
 * 
 * @author LongAndHao
 * @date 2024-11-04
 */
@RestController
@RequestMapping("/mes/line")
public class ProductionLineController extends BaseController
{
    @Autowired
    private IProductionLineService productionLineService;

    /**
     * 查询产线信息列表
     */
//    @PreAuthorize("@ss.hasPermi('mes:line:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductionLine productionLine)
    {
        startPage();
        List<ProductionLine> list = productionLineService.selectProductionLineList(productionLine);
        return getDataTable(list);
    }

    /**
     * 导出产线信息列表
     */
//    @PreAuthorize("@ss.hasPermi('mes:line:export')")
    @Log(title = "产线信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductionLine productionLine)
    {
        List<ProductionLine> list = productionLineService.selectProductionLineList(productionLine);
        ExcelUtil<ProductionLine> util = new ExcelUtil<ProductionLine>(ProductionLine.class);
        util.exportExcel(response, list, "产线信息数据");
    }

    /**
     * 获取产线信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('mes:line:query')")
    @GetMapping(value = "/{lineId}")
    public AjaxResult getInfo(@PathVariable("lineId") Long lineId)
    {
        return success(productionLineService.selectProductionLineByLineId(lineId));
    }

    /**
     * 新增产线信息
     */
//    @PreAuthorize("@ss.hasPermi('mes:line:add')")
    @Log(title = "产线信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductionLine productionLine)
    {
        return toAjax(productionLineService.insertProductionLine(productionLine));
    }

    /**
     * 修改产线信息
     */
//    @PreAuthorize("@ss.hasPermi('mes:line:edit')")
    @Log(title = "产线信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductionLine productionLine)
    {
        return toAjax(productionLineService.updateProductionLine(productionLine));
    }

    /**
     * 删除产线信息
     */
//    @PreAuthorize("@ss.hasPermi('mes:line:remove')")
    @Log(title = "产线信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lineIds}")
    public AjaxResult remove(@PathVariable Long[] lineIds)
    {
        return toAjax(productionLineService.deleteProductionLineByLineIds(lineIds));
    }

    /**
     * 预估年产量
     */
//    @PreAuthorize("@ss.hasPermi('mes:line:list')")
    @GetMapping("/list/pro")
    public Long annualProduction()
    {
        return productionLineService.annualProduction();
    }
    /**
     * 预估单个产线年产量
     */
//    @PreAuthorize("@ss.hasPermi('mes:line:list')")
    @GetMapping("/list/one")
    public List<annualVo> annualProductionList()
    {
        return productionLineService.annualProductionList();
    }
    /**
     * 预估单个产线日产量
     */
//    @PreAuthorize("@ss.hasPermi('mes:line:list')")
    @GetMapping("/list/daily")
    public List<dailyVo> dailyProductionList()
    {
       return productionLineService.dailyProductionList();
    }
    /**
     * 预估所有产线日产量
     */
//    @PreAuthorize("@ss.hasPermi('mes:line:list')")
    @GetMapping("/list/dailyVo")
    public Long dailyProduction()
    {
       return productionLineService.dailyProduction();
    }

    @GetMapping( "/list/pro0")
    public TableDataInfo electProductionLine0(ProductionLine productionLine)
    {
        startPage();
        List<ProductionLine> list = productionLineService.selectProductionLine0(productionLine);
        return getDataTable(list);
    }

}
